<?php


namespace app\common\service\coupon;


class MJCouponDiscount implements CouponDiscount
{

    /**
     * Author:YangXinPeng
     * 满减计算
     * @param $coupon
     * @param $price
     * @return float
     */
    public function discountAmount($coupon, $price)
    {
        /**
         * 满减计算
         * 判断满足x元后-n元，否则不减
         * 最低支付金额1元
         */
        $minPrice = $coupon['use_min_price'];
        $couponPirce = $coupon['coupon_price'];
        if ($price < $minPrice){
            return $price;
        }else{
            $money = bcsub($price,$couponPirce);
            if ($money < 1){
                return (float)1;
            }else{
                return (float)$money;
            }
        }
    }
}